package dayOfYear;

public class Solution {
    public static void main(String[] args) {

    }
    public int dayOfYear(String date) {
        int dayIndex=0;
        int year,month,day;
        year=Integer.parseInt(date.substring(0,4));
        month=Integer.parseInt(date.substring(5,7));
        day=Integer.parseInt(date.substring(8,10));
        if(isRunYear(year)){
            for (int i = 0; i < month; i++) {
                if(i==2){
                  dayIndex+=28;
                }else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                    dayIndex+=31;
                } else{
                    dayIndex+=30;
                }
            }
        }else{
            for (int i = 0; i < month; i++) {
                if(i==2){
                    dayIndex+=29;
                }else if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                    dayIndex+=31;
                } else{
                    dayIndex+=30;
                }
            }

        }
        return dayIndex+day;

    }
    private boolean isRunYear(int year){
        if(year%4==0&&year%100!=0||year%400==0){
            return true;
        }
        return false;
    }
}
//1. 年份是4的倍数而不是100的倍数; 2. 年份是400的倍数